package io.shqyang.myapplication.util;

import java.util.Arrays;
import java.util.Calendar;

public class DateUtils {

    public static String timeNow() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        String time = calendar.get(Calendar.HOUR_OF_DAY)
                + ":"
                + calendar.get(Calendar.MINUTE)
                + ":"
                + calendar.get(Calendar.SECOND);
        return time;
    }

    public static String[] hmsNow() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        String[] r = new String[3];
        Arrays.fill(r, "");
        int h = calendar.get(Calendar.HOUR_OF_DAY);
        if (h < 10) {
            r[0] = "0";
        }
        r[0] += h;

        int m = calendar.get(Calendar.MINUTE);
        if (m < 10) {
            r[1] = "0";
        }
        r[1] += m;

        int s = calendar.get(Calendar.SECOND);
        if (s < 10) {
            r[2] = "0";
        }
        r[2] += s;
        return r;
    }

}
